﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace SimpleNugetServer.Models
{
    [XmlRoot(ElementName = "package", Namespace = "http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd")]
    public class Nuspec2013 : Nuspec
    {
    }

    [XmlRoot(ElementName = "package", Namespace = "http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd")]
    public class Nuspec2012 : Nuspec
    {
    }

    [XmlRoot(ElementName = "package", Namespace = "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd")]
    public class Nuspec2011 : Nuspec
    {
    }

    [XmlType("package")]
    public abstract class Nuspec
    {
        [XmlElement("metadata", IsNullable = false)]
        public NuspecMetadata Metadata { get; set; }

        [XmlArray("files")]
        public List<NuspecFile> Files { get; set; }

        [XmlIgnore]
        public long Size { get; set; }

        [XmlIgnore]
        public string Hash { get; set; }

        [XmlIgnore]
        public string[] TargetFrameworks { get; set; }

        [XmlIgnore]
        public string Path { get; set; }

        public bool IsPrerelease()
        {
            return this.Metadata.Version.Contains("alpha")
                || this.Metadata.Version.Contains("meta")
                || this.Metadata.Version.Contains("rc");
        }

        public override string ToString()
        {
            return Metadata.Id + " " + Metadata.Version;
        }
    }
}
